<?php

namespace App\Http\Controllers\Api\V1\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Brick\Math\RoundingMode;

class CirclesResource extends JsonResource
{
    public function toArray($request)
    {
    	$resource = $this->resource;
    	$sku  = $this->resource->product->skus ?? [];

    	$images = $resource->images;
    	if(!empty($images)){

    		foreach($images as &$image){
    			$image = img_path($image);

    		}
    	}

    	//$seckillProduct  = $this->resource->product->seckillProducts ?? [];

    	$data = [
	        'id' 				=> (int)$resource->id,
	        'title' 			=> (string)$resource->title,
	        'video'             => img_path($resource->video),
	        'images'            => $images,
	        'product'=> isset($resource->product) && $resource->product->is_sale ==true ? $resource->product : null,
	        'rewards'=> !empty($sku) ? $sku->first()->rewards : 0.00,
			'parent_rewards'=>!empty($sku) ? $sku->first()->parent_rewards : 0.00,
			'own_rewards'=> !empty($sku) ? $sku->first()->own_rewards : 0.00,
			'team_rewards'=>!empty($sku) ? $sku->first()->team_rewards : 0.00,
			'price_vip'=> !empty($sku) ? $sku->first()->price_vip : 0.00,
			'price_cost'=> !empty($sku) ? $sku->first()->price_cost : 0.00,
			'price'=> !empty($sku) ? $sku->first()->price : 0.00,
			//'sid'=> $seckillProduct ? $seckillProduct->first()->id : 0,
	        'created_at' => (string)$resource->created_at,
        ];
        unset($data['product']['skus']);
        unset($data['product']['seckillProducts']);


        return $data;
    }
}
